home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Applications / MathPad 2.4 / XFuns / XFun kit / util src / callback.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-01  |  7.0 KB  |  170 lines  |  [TEXT/CWIE]

  1. /*
  2.  Prototypes for MathPad's callback routines.
  3.  
  4.  This header file is for XFuns that do not use ANY A4 globals.
  5.  In this case you can get by without doing SetUpA4 etc.
  6.  The file "callback.c" implements these routines. The callback
  7.  pointer must be passed to each routine.
  8.  
  9.  The compiler must be set so that type "double" is a SANE 80-bit.
  10.  
  11. */
  12.  
  13. typedef short (*funptr) (...);
  14. typedef struct expr    *EXPR;    /* internal details aren't needed by XFun */
  15.  
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19.  
  20. /* ---------- control routines ---------------------------- */
  21.  
  22. extern void AddXfun(char *name,char *parms,funptr entry,funptr predef,funptr callback);
  23.   /* Install a new function from a code resource. */
  24.   //(internally defined a static)
  25.   
  26. extern void AddFunDim(char *name, long lim,funptr callback);
  27.   /* Setup routine to allow the XFun to return values based on the array index.
  28.    This routine must be called by the predef routine. It can be called multiple times
  29.    to set up a multidimensional return value. Array index values are appended to the
  30.    parameter list */
  31.  
  32. extern void ErrMsg(char *fmt,char *str,funptr callback);
  33.   /* Show an error message in the status line.
  34.     fmt is a printf() format string. str is an optional parameter
  35.     Sets stop flag to tell MathPad to stop all evaluation. */
  36.  
  37. extern short Stopped(funptr callback);
  38.   /* Check value of stop flag to see if evaluation should be stopped. */
  39.  
  40. extern void SpinWatch(funptr callback);
  41.   /* Allow a computation to be switched to background or stopped via command period.
  42.    Stopped() must be checked to see if command period was hit.
  43.    SpinWatch() should be called at least twice per second.
  44.    It can be called at a much higher rate without much loss. */
  45.  
  46. extern void ReturnVoid(funptr callback);
  47.   /* Allow the XFun to return false without generating an error message. */
  48.  
  49.  
  50. /* ------------- function parameter access ---------------- */
  51. /* Parameters are numbered from right to left starting at 0 */
  52.  
  53. extern short GetParmVal(long n,double *num,funptr callback);
  54.   /* Get the value of a simple numeric parameter.
  55.    Returns false if the value is an array or undefined */
  56.  
  57. extern void MakeParmExpr(long n,EXPR *xpr,funptr callback);
  58.   /* Make a parameter expression. (Used to access arrays).
  59.    The expression must be deallocated with FreeExpr(xpr). */
  60.  
  61. extern short GetParmName(long n,char **name,funptr callback);
  62.   /* Get a name parameter. (Used to get a filename or other string).
  63.     Returns false if the parameter was an expression or defined variable */
  64.  
  65.  
  66.  
  67. /* ------------------ global variable access ---------------- */
  68.  
  69. extern short GetVarVal(char *name,double *num,funptr callback);
  70.   /* Evaluate the named global variable.
  71.     Returns false if the value is an array or undefined */
  72.  
  73. extern void GetVarString(char *name,char **str,funptr callback);
  74.   /* Returns the string value of a named global variable.
  75.     Returns an empty string if unless the variable was set to a string */
  76.  
  77. extern void MakeVarExpr(char *name,EXPR *xpr,funptr callback);
  78.   /* Make a global variable expression. (Used to access arrays).
  79.    The expression must be deallocated with FreeExpr(xpr). */
  80.  
  81. extern short SetVarVal(char *name,double num,funptr callback);
  82.   /* Assign a single value to the named global variable.
  83.      Returns false if the variable is an illegal destination. */
  84.  
  85. extern short SetVarMatrix(char *name,double *arr,long rows,long cols,funptr callback);
  86.   /* Assign a 1D or 2D array to the named global variable. 
  87.      Returns false if the variable is an illegal destination.
  88.      The array must be allocated via NewPtr() and will be deallocated by MathPad. */
  89.  
  90. extern void FoldVar(char *name,long lim,funptr callback);
  91.   /* Add a dimension to the variable set by SetVarMatrix(). Can be called multiple
  92.      times to create more dimensions. */
  93.  
  94.  
  95.  
  96. /* ------------ general expression routines ----------------- */
  97.  
  98. extern short GetExprMatrix(EXPR xpr,double **mat,long *rows,long *cols,funptr callback);
  99.   /* Allocate memory and evaluate all elements of a 1D or 2D matrix expression into memory.
  100.    Returns a pointer to the matrix in mat.
  101.    A scalar will return cols=0 and rows=0. A 1D array will return cols=0.
  102.    An array with more than 2 dimensions will generate an error message and return false.
  103.    The matrix allocated by GetExprMatrix() should be deallocated with DisposPtr() */
  104.  
  105. extern short ProbeExpr(EXPR xpr,double *num,short *isarray,long *count,funptr callback);
  106.   /* Find out if an expression is a scalar or an array.
  107.    If scalar, returns true and sets num.
  108.    If array, returns false and sets isarray and count. A count of 0 means infinite array.
  109.    If the return value and isarray are both false the expression was undefined. */
  110.  
  111. extern void AddIndex(EXPR *xpr,double **iptr,funptr callback);
  112.   /* Add an index to allow evaluating individual array elements.
  113.    The double at iptr can be modified to index through the array.
  114.    To access a single element, an index must be added for each dimension of the array. */
  115.  
  116. extern void RemoveIndex(EXPR *xpr,funptr callback);
  117.   /* Can be used to remove the last index added by AddIndex(). Normally FreeExpr() is
  118.     be used to free the entire expression so this call is not required. */
  119.  
  120. extern short EvalExpr(EXPR xpr,double *num,funptr callback);
  121.   /* Evaluate an expression. Returns false if xpr is an array or undefined.*/   
  122.  
  123. extern void FreeExpr(EXPR xpr,funptr callback);
  124.   /* Free memory allocated to an expression.
  125.    Use to deallocate from MakeParmExpr() or MakeVarExpr() */
  126.  
  127.  
  128. /* ---------- PICT overlay ---------------- */
  129.  
  130. extern void SetPlotPICT(PicHandle thePic,funptr callback);
  131.   /* Allows an XFun to overlay PICT graphics on the plot. Overlay goes on current strip.
  132.    The XFun must allocate and create thePic. MathPad will dispose of it.  */
  133.  
  134. extern void SizePlotPICT(double left,double bot,double width,double ht,funptr callback);
  135.   /* Specify where to draw the PICT in data coordinates.
  136.     Default is to size the PICT to fill the data plot area.  */
  137.  
  138.  
  139. /* ---------- Document info ----------- */
  140.  
  141. short GetDocInfo(long *docref,FSSpec *fspec,WindowPtr *plotwindow,funptr callback);
  142.   /* Get info about the document being evaluated. Returns false if no doc is open. */
  143.  
  144. extern void GetAngleUnits(double *unit,funptr callback);
  145.   /* Get the currently selected multiplier trig function parameters.
  146.      1.0 for radians, .017 for degrees */
  147.  
  148. extern void GetAxisRect(Rect *axisrect,funptr callback);
  149.   /* Get the current data axis rectangle in plot window coordinates */
  150.  
  151. extern void GetAxisLimits(double limits[6],funptr callback);
  152.   /* Get the the current values of xmin,xmax,ymin,ymax,zmin,zmax */
  153.  
  154. extern void GetPlotInfo(double info[12],funptr callback);
  155.   /* Get the the current values of xlo,xhi,ylo,yhi,zlo,zhi,
  156.      traceclick,xclick,yclick,zclick,ixclick,iyclick */
  157.  
  158.   
  159. /* -------------- Utillity --------------------*/
  160. extern short Sprintf(char *buf,char *fmt,double num,funptr callback);
  161.   /* Allows XFun some access to sprintf() without linking its own ANSI library */
  162.  
  163. extern void MapData(double x,double y,short *xpixel,short *ypixel,funptr callback);
  164.   /* use current plot window scaling to convert data coords to pixel coords */
  165.  
  166.  
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170.